package com.hengxing.controller;


import com.hengxing.exception.BusinessException;
import com.hengxing.exception.SystemException;
import org.apache.ibatis.jdbc.Null;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * 请求异常处理器
 */
@RestControllerAdvice
public class ProjectExceptionAdvice {


    @ExceptionHandler(SystemException.class)
    public Result doSystemException(SystemException err) {
        //记录日志
        //发送消息给运维
        //发送邮件给开发人员
        return new Result(err.getCode(), null, err.getMessage());
    }

    @ExceptionHandler(BusinessException.class)
    public Result doBunsinessException(BusinessException err) {
        //记录日志
        //发送消息给运维
        //发送邮件给开发人员
        return new Result(err.getCode(), null,err.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result doException(Exception err) {
        System.out.println("出现未知异常，通知大家开会处理.......");
        return new Result(Code.UNKNOW_ERR, null,Code.UNKNOW_ERR_MSG);
    }
}
